<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<SCRIPT TYPE="text/javascript">

//This function is for making a pop up window when you press "Buy Ticket Online"

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=450,height=350,scrollbars=yes');
return false;
}

</SCRIPT>
<style type="text/css">
body
{
background-image:url('images/Aquarius-logo.png');
background-repeat:no-repeat;
}
h3{
font-style: italic;
position:fixed;
top:55px;
left:319px;
}
div{
position:fixed;
top:80px;
right:10px;
}
#movie_table
{
position:fixed;
top:120px;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Front Page</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>

<?php
include_once ("common.php");
printHeader();
?>


<h3>Welcome to Our Movie Theater</h3>
<p>&nbsp;</p>


<div align="right">

<form name=form method=post action="search-feedback.php">
<input type=text name=moviefeedback size="12"><input type=submit value="search movie"></td>
</form>

<table>
<tr><td height="40"/></tr>
</table>

<?php
// session_start();
if (!isset ($_SESSION['SESS_MEMBER_ID'])) {
	echo '
	<form id="loginForm" name="loginForm" method="post" action="login-exec.php">
	  <table border="0" cellpadding="2" cellspacing="0">
	    <tr>
	      <td width="70"><b>Login</b></td>
	      <td><input name="userid" type="text" class="textfield" id="userid" /></td>
	    </tr>
	    <tr>
	      <td><b>Password</b></td>
	      <td><input name="password" type="password" class="textfield" id="password" /></td>
	    </tr>
	    <tr>
	      <td>&nbsp;</td>
	      <td><input type="submit" name="Submit" value="Login" /></td>
	    </tr>
	    <tr>
	    <td><a href="register-form.php">Register</a></td></td>
	    </tr>
	  </table>
	</form>
	';
}
?>

</div>
</body>
</html>


<!-- Displaying Movie details on the home page -->
<?php
require_once ('config.php');

$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$con) {
	die('Could not connect: ' . mysql_error());
}

mysql_select_db(DB_DATABASE, $con);

echo "<table id=\"movie_table\" border=1>";

$result = mysql_query("select name, picture_path, synopsis from movielist", $con);
echo "<tr>";
$movie_names = array ();
$synopses = array ();
while ($row = mysql_fetch_array($result)) {
	$path = "$row[picture_path]";
	echo "<td><a href='search-feedback.php?movie=$row[name]' title='$row[name]'><img src='$path' width=140px height=180px alt='$path'></a></td>";
	$movie_names[] = $row['name'];
	$synopses[] = $row['synopsis'];
} //end of for loop
echo "</tr>";
#echo "<tr>";
#foreach ($movie_names as $movie_name) {
#	echo "<td><a href='search-feedback.php?movie=$movie_name'>($movie_name)</a> </td>";
#}
#echo "</tr>";

echo "<tr>";
foreach ($synopses as $synopsis) {
	echo "<td valign=top width=140px>$synopsis </td>";
}
echo "</tr>";

echo "<tr>";
foreach ($movie_names as $movie_name) {
	$sql = "select s.showtime from showtimes s, movielist m where m.ID = s.movieID and m.name='$movie_name'";
	$result = mysql_query($sql);
	echo "<td>";
	while ($row = mysql_fetch_array($result)) {
	  $time = substr($row[showtime], 0, 5);
	  $sql = "select s.available_tickets from showtimes s, movielist m where m.ID=s.movieID and m.name = '$movie_name' and s.showtime = '$time'";
      $available_tix = mysql_fetch_row(mysql_query($sql));
      $available_tix = intval($available_tix[0]);
	  
	  if ($available_tix > 0) {
	    echo "$time (<a href='buy_ticket.php?movie=$movie_name&time=$time'>$available_tix</a>) ";
	  } else {
	  	echo "$time ";
	  }
	}
	echo "</td>";
}
echo "</tr>";

echo "</table>";
?>

